import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:top_foundation/component/window/window.dart';
import 'package:top_foundation/utils/ex/image.dart';
import 'package:top_foundation/utils/theme/button.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/component/search/index.dart';
import 'package:whale/helper/utils/um/event.dart';
import 'package:whale/helper/utils/um/um_man.dart';
import 'package:whale/helper/utils/util.dart';
import 'package:whale/helper/utils/version/check_update.dart';
import 'package:whale/pages/audio/index.dart';
import 'package:whale/pages/button/index.dart';
import 'package:whale/pages/download_demo/index.dart';
import 'package:whale/pages/grid/index.dart';
import 'package:whale/pages/home/main/widgets/pop_page.dart';
import 'package:whale/pages/home/subs/page_window_demo/index.dart';
import 'package:whale/pages/paint_demo/index.dart';
import 'package:whale/pages/popup_demo/index.dart';
import 'package:whale/pages/progress_demo.dart/index.dart';

import '../../../casstle_demo/index.dart';
import '../../../medio_picker/index.dart';
import '../../../refresh_demo/index.dart';
import '../index.dart';

/// hello
class HelloWidget extends GetView<HomeController> {
  const HelloWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    return Container(
      child: ListView(
        children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Hero(
              tag: 'search',
              child: IButton.create(
                onPressed: () {
                  // UmMan().onEvent(event: UmEvent.home_search);
                  // UmMan().onEvent(event: UmEvent.search, param: {
                  //   'Um_Key_SearchKeyword': '搜',
                  //   'Um_Key_SearchPortal': 'home',
                  //   'Um_key_SearchRecommend': '无',
                  //   'Um_Key_UserID': '1',
                  //   'Um_Key_UserLevel': '钻石',
                  // });
                  Get.to(
                    () => SearchPage(),
                    transition: Transition.noTransition,
                    binding: SearchBinding(),
                  );
                },
                child: Container(
                  height: 40.r,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: ITheme.disableBgColor,
                    borderRadius: BorderRadius.circular(22.r),
                  ),
                  child: Row(
                    children: [
                      SizedBox(
                        width: 10.r,
                      ),
                      Icon(
                        IconUtil.search,
                        size: 15.w,
                        color: ITheme.hintColor,
                      ),
                      SizedBox(
                        width: 10.r,
                      ),
                      Text('搜索', style: ITheme.text.hintStyle),
                    ],
                  ),
                ),
              ),
            ),
          ),
          CarouselSlider.builder(
            itemCount: state.carouselList.length,
            options: CarouselOptions(
              // reverse: true,
              enlargeCenterPage: true,
              autoPlay: true,
            ),
            itemBuilder:
                (BuildContext context, int itemIndex, int pageViewIndex) =>
                    IImage.net(
                        url: state.carouselList[itemIndex],
                        fit: BoxFit.cover,
                        width: 1.sw),
          ),
          Textcell(
            text: 'dialog--各种弹窗',
            onTap: () {
              Get.to(() => PopupDemoPage(), binding: PopupDemoBinding());
            },
          ),
          Textcell(
            text: '全局窗口---长按消失，可拖动',
            onTap: () {
              IWindow.show(
                GestureDetector(
                  onLongPress: () {
                    IWindow.dismiss(name: 'name');
                  },
                  child: Container(
                    width: 100,
                    height: 100,
                    color: Colors.amber,
                  ),
                ),
                name: 'name',
                isPan: true,
              );
            },
          ),
          Textcell(
            text: '页面小窗口',
            onTap: () {
              Get.to(() => PageWindowDemoPage(),
                  binding: PageWindowDemoBinding());
            },
          ),
          Textcell(
              onTap: () {
                Get.to(() => GridPage(), binding: GridBinding());
              },
              text: 'grid--瀑布流及方块布局'),
          Textcell(
            text: 'im',
            onTap: () {
              Get.toNamed(RouterPath.im_list);
            },
          ),
          Textcell(
            text: '检查更新',
            onTap: () {
              CheckUpdate().checkUpdate();
            },
          ),
          Textcell(
            text: '图片，文件，视频选择器',
            onTap: () {
              Get.to(() => MedioPickerPage(), binding: MedioPickerBinding());
            },
          ),
          Textcell(
              onTap: () {
                Get.toNamed(RouterPath.web_view, parameters: {
                  'url': 'https://jixiao.inspirestar.cn/assessment-app/#/login',
                });
              },
              text: '浏览器'),
          Textcell(
              onTap: () {
                Get.to(() => PaintDemoPage(), binding: PaintDemoBinding());
              },
              text: '绘制'),
          Textcell(
              onTap: () {
                Get.to(() => ProgressDemoDartPage(),
                    binding: ProgressDemoDartBinding());
              },
              text: '进度'),
        ],
      ),
    );
  }
}

class Textcell extends StatelessWidget {
  const Textcell({
    super.key,
    required this.text,
    required this.onTap,
  });
  final String text;
  final VoidCallback onTap;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 12.r),
        alignment: Alignment.centerLeft,
        height: 50.r,
        decoration: BoxDecoration(
          border: Border(
            bottom: ITheme.borderSide,
          ),
        ),
        child: Text(
          text,
          style: TextStyle(
            color: Colors.black,
            fontSize: 15.sp,
          ),
        ),
      ),
    );
  }
}
/**
  1、绩效产品化移动端适配升级sdk，依赖库升级，页面刷新统一封装替换处理，弹窗组件统一替换成基础库弹窗组件，页面toast文件替换成自定义组件，增加页面统一性。
  2、熟悉绩效产品化前端代码结构
 */